const fs = require('fs');
const path = require('path');
const JSON5 = require('json5');
const Mock = require('mockjs');

function getJson5File(filePath) {
  var jsonData = fs.readFileSync(path.join(__dirname, './test.json5'), 'utf-8');
  return JSON5.parse(jsonData);
}

module.exports = function (app) {
  console.log();
  console.log("/mock/index.js", process.env.MOCK);
  console.log("/mock/index.js", typeof process.env.MOCK);
  if (process.env.MOCK == "true") {
    app.get("/mock/user/userInfo", function (req, res) {
      var jsonObj = getJson5File('./test.json5');
      res.json(Mock.mock(jsonObj));
    });
  }
}
